var ServerDomain = "http://" + window.location.host + "/index.php/"

function checkLogin() {
    var lastLoginTime = localStorage.getItem('lastLoginTime')
    if (lastLoginTime != null && ((Math.round(new Date() / 1000) - Number(lastLoginTime)) <= 86400)) {
        return true
    } else {
        return false
    }

}

function loginOut() {
    localStorage.clear()
}

function saveLogin(username, memberID,rememberMe) {
    localStorage.setItem('username', username)
    localStorage.setItem('memberID', memberID)
    if(rememberMe==true){
        localStorage.setItem('lastLoginTime', Math.round(new Date() / 1000)+2592000)
    }else{
        localStorage.setItem('lastLoginTime', Math.round(new Date() / 1000))
    }
}
function p($item) {
    console.dir($item)
}


function AjaxPost(url, postData) {
    url = ServerDomain + url
    var result
    $.ajax({
        type: "POST",
        url: url,
        data: postData,
        async: false,
        dataType: "json",
        success: function (data) {
            result = data
        },
    })
    return result
}


function AjaxPostAsync(url, postData, callback) {
    url = ServerDomain + url
    var result
    $.ajax({
        type: "POST",
        url: url,
        data: postData,
        async: true,
        dataType: "json",
        success: function (data) {
            result = data
            callback(result)
        },
    })
}

function AjaxGet(url, postData) {
    url = ServerDomain + url
    var result
    $.ajax({
        type: "get",
        url: url,
        data: postData,
        async: false,
        dataType: "json",
        success: function (data) {
            result = data
        },
    })
    return result
}

function AjaxGetAsync(url, postData, callback) {
    url = ServerDomain + url
    $.ajax({
        type: "get",
        url: url,
        data: postData,
        async: true,
        dataType: "json",
        success: function (data) {
            callback(data)
        },
        error: function (err) {
            console.dir(err)

        }
    })
}

function getUrlParamValue(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) {
        return unescape(r[2]);
    } else {
        return null;
    }

}
